﻿'Imports ZedGraph
'Imports System.Text

''/*
'' * FAHWatch7  Copyright Marvin Westmaas ( mtm )
'' *
'' * This program is free software; you can redistribute it and/or
'' * modify it under the terms of the GNU General Public License
'' * as published by the Free Software Foundation; version 2
'' * of the License. See the included file GPLv2.TXT.
'' * 
'' * This program is distributed in the hope that it will be useful,
'' * but WITHOUT ANY WARRANTY; without even the implied warranty of
'' * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
'' * GNU General Public License for more details.
'' * 
'' * You should have received a copy of the GNU General Public License
'' * along with this program; if not, write to the Free Software
'' * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301, USA.
'' */
''/*	
'Public Class frmFWatch
'    Public bManual As Boolean = False
'    Private dtLastRefresh As DateTime
'    Private Sub LogMessagesToolStripMenuItem_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles LogMessagesToolStripMenuItem.Click
'        If LogWindow.IsWindowActive Then
'            LogWindow.HideDebugWindow()
'        Else
'            LogWindow.ShowDebugWindow(My.Resources.iLog)
'        End If
'    End Sub
'    Public Delegate Sub DoAddDynamic(ByVal NewItem As ListViewItem)
'    Public Sub AddDynamic(ByVal NewItem As ListViewItem)
'        'Try
'        '    If lvActive.InvokeRequired Then
'        '        Dim nDo As New DoAddDynamic(AddressOf AddDynamic)
'        '        lvActive.Invoke(nDo, {NewItem})
'        '    Else
'        '        lvActive.Items.Add(NewItem)
'        '    End If
'        'Catch ex As Exception
'        '    LogWindow.WriteError(ex.Message, Err)
'        'End Try
'    End Sub
'    Public Delegate Sub DoClear()
'    Public Sub ClearActive()
'        'Try
'        '    If lvActive.InvokeRequired Then
'        '        Dim nC As New DoClear(AddressOf ClearActive)
'        '        lvActive.Invoke(nC)
'        '    Else
'        '        lvActive.Items.Clear()
'        '    End If
'        'Catch ex As Exception
'        '    LogWindow.WriteError(ex.Message, Err)
'        'End Try
'    End Sub
'    Public Delegate Sub DoSuspend()
'    Public Sub SuspendActive()
'        'Try
'        '    If lvActive.InvokeRequired Then
'        '        Dim nS As New DoSuspend(AddressOf SuspendActive)
'        '        lvActive.Invoke(nS)
'        '    Else
'        '        lvActive.SuspendLayout()
'        '    End If
'        'Catch ex As Exception
'        '    LogWindow.WriteError(ex.Message, Err)
'        'End Try
'    End Sub
'    Public Delegate Sub StopSuspend()
'    Public Sub StopSuspendLayout()
'        'Try
'        '    If lvActive.InvokeRequired Then
'        '        Dim nR As New StopSuspend(AddressOf StopSuspendLayout)
'        '        lvActive.Invoke(nR)
'        '    Else
'        '        lvActive.ResumeLayout()
'        '        Application.DoEvents()
'        '        lvActive.AutoResizeColumns(ColumnHeaderAutoResizeStyle.ColumnContent)
'        '        lvActive.AutoResizeColumns(ColumnHeaderAutoResizeStyle.HeaderSize)
'        '    End If
'        'Catch ex As Exception
'        '    LogWindow.WriteError(ex.Message, Err)
'        'End Try
'    End Sub
'#Region "Historical listview functions"
'    Private Function lvItemForHistory(ByVal ClientName As String, ByVal WU As clsLogParser.clsClient.clsLogFile.clsWU) As ListViewItem
'        Try
'            Dim nI As New ListViewItem
'            nI.Text = ClientName
'            nI.SubItems.Add(WU.Slot)
'            nI.SubItems.Add(WU.HW)
'            nI.SubItems.Add(WU.PRCG)
'            nI.SubItems.Add(WU.dtDownloaded.ToString)
'            nI.SubItems.Add(WU.dtSubmitted.ToString)
'            nI.SubItems.Add(WU.WS)
'            nI.SubItems.Add(WU.Core)
'            nI.SubItems.Add(WU.CoreVersion)
'            nI.SubItems.Add(WU.CoreStatus)
'            If WU.CoreStatus <> "" And Not WU.CoreStatus.Contains("(100)") Then
'                nI.BackColor = Color.Red
'            End If
'            nI.SubItems.Add(WU.ServerResponce)
'            'Credit!
'            If WU.ServerResponce.Contains("(400)") Then
'                'Valid credit
'                If WU.Credit <> "" Then
'                    'Use server provided credit
'                    nI.SubItems.Add(WU.Credit)
'                    'Lightblue for server credit 
'                    nI.BackColor = Color.LightBlue
'                Else
'                    'Try to get from project info 
'                    If WU.Percentage = "100" AndAlso projectInfo.Projects.KnownProject(WU.PRCG.Substring(Len("project:"), WU.PRCG.IndexOf(" ") - Len("project:"))) AndAlso WU.dtSubmitted <> #1/1/2000# Then
'                        nI.SubItems.Add(projectInfo.GetEffectivePPD_sqrt(WU.dtDownloaded, WU.dtSubmitted, WU.PRCG.Substring(Len("project:"), WU.PRCG.IndexOf(" ") - Len("project:"))).Credit)
'                        'Light green for psummary info
'                        nI.BackColor = Color.LightGreen
'                    Else
'                        nI.SubItems.Add("")
'                    End If
'                End If
'            Else
'                If WU.ServerResponce <> "" Or WU.dtCompleted <> #1/1/2000# Then nI.BackColor = Color.Red 'Check this!
'                nI.SubItems.Add("")
'            End If
'            'PPD!
'            If WU.Credit <> "" Then
'                'New method; if credit is known, check timespan dtsubmitted.substract(dtDownloaded) and check how many times a day it fits
'                If WU.dtSubmitted <> #1/1/2000# And WU.ServerResponce.Contains("(400)") Then
'                    Dim tsProject As TimeSpan = WU.dtSubmitted.Subtract(WU.dtDownloaded)
'                    Dim iPworth As Integer = CInt(WU.Credit)
'                    Dim iPPD As Double = 0
'                    Dim tsDay As TimeSpan = TimeSpan.FromDays(1)
'                    Do
'                        If tsDay.Subtract(tsProject).TotalSeconds >= 0 Then
'                            iPPD += iPworth
'                            tsDay = tsDay.Subtract(tsProject)
'                        Else
'                            Exit Do
'                        End If
'                    Loop
'                    'get fraction of _tsFrame to be done in remaining seconds
'                    Dim iRfraction As Double
'                    If tsDay.TotalSeconds > 0 Then
'                        iRfraction = tsDay.TotalSeconds / tsProject.TotalSeconds
'                        iPPD += iRfraction * iPworth
'                    End If
'                    nI.SubItems.Add(Math.Round(iPPD, 2).ToString)
'                Else
'                    nI.SubItems.Add("")
'                End If
'            Else
'                'Check projectinfo
'                'Try to get from project info 
'                If WU.Percentage = "100" AndAlso projectInfo.Projects.KnownProject(WU.PRCG.Substring(Len("project:"), WU.PRCG.IndexOf(" ") - Len("project:"))) AndAlso WU.dtSubmitted <> #1/1/2000# Then
'                    nI.SubItems.Add(projectInfo.GetEffectivePPD_sqrt(WU.dtDownloaded, WU.dtSubmitted, WU.PRCG.Substring(Len("project:"), WU.PRCG.IndexOf(" ") - Len("project:"))).PPD)
'                    'Light green for psummary info
'                    nI.BackColor = Color.LightGreen
'                Else
'                    nI.SubItems.Add("")
'                End If
'            End If
'            nI.SubItems.Add(WU.bHasRestarted.ToString)
'            nI.Tag = WU.unit
'            Return nI
'        Catch ex As Exception
'            LogWindow.WriteError(ex.Message, Err)
'            Return New ListViewItem
'        End Try
'    End Function
'    Private Sub CheckWUForHistory(ByVal ClientName As String, ByVal Wu As clsLogParser.clsClient.clsLogFile.clsWU)
'        Try
'            If Wu.CoreStatus <> "" Then
'                If _tsFilterCS <> "" And Wu.CoreStatus <> _tsFilterCS Then
'                    GoTo Skip
'                End If
'                If _tsFilterHW <> "" And Wu.HW <> _tsFilterHW Then
'                    GoTo Skip
'                End If
'                If _tsFiltersSL <> "" And Wu.Slot <> _tsFiltersSL Then 'Fix spelling later!!!
'                    GoTo Skip
'                End If
'                If _tsFiltersPR <> "" And Not Wu.PRCG.Substring(Len("project:"), Wu.PRCG.IndexOf(" ") - Len("project:")) = _tsFiltersPR Then
'                    GoTo Skip
'                End If
'                If Wu.CoreStatus <> "" Then
'                    Dim nI As ListViewItem = lvItemForHistory(ClientName, Wu)
'                    lvWU.Items.Add(nI)
'                End If
'Skip:
'            End If
'        Catch ex As Exception
'            LogWindow.WriteError(ex.Message, Err)
'        End Try
'    End Sub
'#End Region
'    'Private Sub tscmbLFiles_SelectedIndexChanged(ByVal sender As Object, ByVal e As System.EventArgs) Handles tscmbLFiles.SelectedIndexChanged
'    '    Try
'    '        If bManual Or tscmbLFiles.SelectedIndex = -1 Then Exit Sub
'    '        bManual = True
'    '        rtfSnippet.Clear()
'    '        rtfPStats.Clear()
'    '        zgProject.MasterPane.PaneList.Clear()
'    '        Dim nP As New GraphPane
'    '        nP.Rect = SplitContainer3.Panel1.ClientRectangle
'    '        zgProject.MasterPane.Add(nP)
'    '        zgProject.Refresh()
'    '        lvWU.Items.Clear()
'    '        lvWU.SuspendLayout()
'    '        Try
'    '            If tscmbClient.SelectedIndex = 0 Then
'    '                'All clients
'    '                If tscmbLFiles.SelectedIndex = 0 Then
'    '                    'All wu's
'    '                    For Each Client As clsLogParser.clsClient In LogParser.Clients
'    '                        For Each logSection As clsLogParser.clsClient.clsLogFile In Client.lstLogFiles
'    '                            For Each wu As clsLogParser.clsClient.clsLogFile.clsWU In logSection.lstWU
'    '                                CheckWUForHistory(Client.ClientName, wu)
'    '                            Next
'    '                        Next
'    '                    Next
'    '                    lvWU.ResumeLayout(True)
'    '                Else
'    '                    'All clients limited logsection
'    '                    lvWU.Items.Clear()
'    '                    'Local client first 
'    '                    For Each Client In LogParser.Clients
'    '                        If Client.dLogFiles.ContainsKey(tscmbLFiles.Items(tscmbLFiles.SelectedIndex).ToString) Then
'    '                            For Each WU In Client.dLogFiles(tscmbLFiles.Items(tscmbLFiles.SelectedIndex).ToString).dWU.Values.ToList
'    '                                CheckWUForHistory(Client.ClientName, WU)
'    '                            Next
'    '                        End If
'    '                    Next
'    '                End If
'    '            ElseIf tscmbClient.SelectedIndex = 1 Then
'    '                'Local client
'    '                If tscmbLFiles.SelectedIndex = 0 Then
'    '                    'All wu's
'    '                    For Each LogSection In LogParser.Clients(0).dLogFiles.Values.ToList
'    '                        For Each WU In LogSection.dWU.Values.ToList
'    '                            CheckWUForHistory(LogParser.Clients(0).ClientName, WU)
'    '                        Next
'    '                    Next
'    '                Else
'    '                    For Each WU In LogParser.Clients(0).dLogFiles(tscmbLFiles.Items(tscmbLFiles.SelectedIndex).ToString).dWU.Values.ToList
'    '                        CheckWUForHistory(LogParser.Clients(0).ClientName, WU)
'    '                    Next
'    '                End If
'    '            Else
'    '                'Remote client
'    '                If tscmbLFiles.SelectedIndex = 0 Then
'    '                    'All wu's
'    '                    For Each LogSection In LogParser.Clients(tscmbClient.SelectedIndex - 1).dLogFiles.Values.ToList
'    '                        For Each wu In LogSection.lstWU
'    '                            CheckWUForHistory(LogParser.Clients(tscmbClient.SelectedIndex - 1).ClientName, wu)
'    '                        Next
'    '                    Next
'    '                Else
'    '                    With LogParser.Clients(tscmbClient.SelectedIndex - 1).dLogFiles(tscmbLFiles.Items(tscmbLFiles.SelectedIndex).ToString)
'    '                        For Each wu In .lstWU
'    '                            CheckWUForHistory(LogParser.Clients(tscmbClient.SelectedIndex - 1).ClientName, wu)
'    '                        Next
'    '                    End With
'    '                End If
'    '            End If
'    '        Catch ex As Exception
'    '            LogWindow.WriteError(ex.Message, Err)
'    '        End Try
'    '        lvWU.AutoResizeColumns(ColumnHeaderAutoResizeStyle.ColumnContent)
'    '        lvWU.AutoResizeColumns(ColumnHeaderAutoResizeStyle.HeaderSize)
'    '        bManual = False
'    '        If lvWU.Items.Count > 0 Then lvWU.Items(0).Selected = True
'    '        Call lvWU_SelectedIndexChanged(Me, Nothing)
'    '    Catch ex As Exception
'    '        LogWindow.WriteError(ex.Message, Err)
'    '    End Try
'    'End Sub
'    Private Sub tscmbClient_SelectedIndexChanged(ByVal sender As Object, ByVal e As System.EventArgs) Handles tscmbClient.SelectedIndexChanged
'        Try
'            If bManual Or tscmbClient.SelectedIndex = -1 Then Exit Sub
'            bManual = True
'            'Fill tscmbFiles with selection from selected client
'            If tscmbClient.SelectedIndex = 0 Then
'                'Add all machines and logs
'                tscmbLFiles.Items.Clear()
'                tscmbLFiles.Items.Add("--All--")
'                For Each Client In LogParser.Clients
'                    For Each LogSection In Client.lstLogFiles
'                        tscmbLFiles.Items.Add(LogSection.Log.Replace("*", "").Trim)
'                    Next
'                Next
'            ElseIf tscmbClient.SelectedIndex = 1 Then
'                'Local
'                tscmbLFiles.Items.Clear()
'                tscmbLFiles.Items.Add("--All--")
'                For Each lS In LogParser.Clients(0).lstLogFiles
'                    tscmbLFiles.Items.Add(lS.Log.Replace("*", "").Trim)
'                Next
'            Else
'                'Remote 
'                tscmbLFiles.Items.Clear()
'                tscmbLFiles.Items.Add("--All--")
'                For Each lS In LogParser.Clients(tscmbClient.SelectedIndex - 1).lstLogFiles
'                    tscmbLFiles.Items.Add(lS.Log.Replace("*", "").Trim)
'                Next
'            End If
'        Catch ex As Exception
'            LogWindow.WriteError(ex.Message, Err)
'        End Try
'        bManual = False
'        tscmbLFiles.SelectedIndex = 0
'    End Sub
'    Private Sub frmFWatch_Activated(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Activated
'        Try
'            Static bOnce As Boolean = False
'            If bOnce Then Exit Sub
'            bOnce = True
'            RefreshUI()
'        Catch ex As Exception
'            LogWindow.WriteError(ex.Message, Err)
'        End Try
'    End Sub
'    Public Sub RefreshUI()
'        Try
'            tscmbClient.Items.Clear()
'            tscmbLFiles.Items.Clear()
'            tscmbClient.Items.Add("--All--")
'            tscmbLFiles.Items.Add("--All--")
'            Dim iWUTotal As Integer, iEUETotal As Integer, iCREDIT As Integer, tsComputation As TimeSpan, tsWaiting As TimeSpan
'            For Each Client In LogParser.Clients
'                tscmbClient.Items.Add(Client.ClientName)
'                'iWUTotal += CInt(Client.Statistics.WU_Completed)
'                'iEUETotal += CInt(Client.Statistics.WU_EUE)
'                'iCREDIT += CInt(Client.Statistics.TotalCredit)
'                'tsComputation.Add(TimeSpan.Parse(Client.Statistics.ComputationTime))
'                'tsWaiting.Add(TimeSpan.Parse(Client.Statistics.WaitingTime))
'                For Each lSection As clsLogParser.clsClient.clsLogFile In Client.lstLogFiles
'                    tscmbLFiles.Items.Add(lSection.Log.Replace("*", "").Trim)
'                Next
'            Next
'            Dim sb As New StringBuilder
'            sb.AppendLine("Work units completed: " & vbTab & iWUTotal.ToString)
'            sb.AppendLine("Early Unit Ends: " & vbTab & iEUETotal.ToString)
'            sb.AppendLine("Succes rate: " & vbTab & vbTab & (100 - (iEUETotal / (iWUTotal / 100))) & "%")
'            sb.AppendLine("Total processing time: " & vbTab & tsComputation.ToString)
'            'Waiting time counts only upload, adding download can only be done when the slot has no active work unit while waiting for an assignment 
'            sb.AppendLine("Total unit waiting time: " & vbTab & tsWaiting.ToString)
'            sb.AppendLine("Total credit: " & vbTab & vbTab & iCREDIT.ToString)
'            rtfSStats.Text = sb.ToString
'            sb = Nothing
'            'bManual = True
'            tscmbClient.SelectedIndex = 0
'            tscmbLFiles.SelectedIndex = 0
'            UpdateActive()
'            'bgActive.RunWorkerAsync()
'            dtLastRefresh = DateTime.Now
'        Catch ex As Exception
'            LogWindow.WriteError(ex.Message, Err)
'        End Try
'    End Sub
'    Private Sub HistoricalWUSelection(ByVal LogSection As clsLogParser.clsClient.clsLogFile, ByVal WU As clsLogParser.clsClient.clsLogFile.clsWU)
'        Try
'            rtfSnippet.Text = WU.CoreSnippet
'            rtfClient.Text = logSection.ClientInfo.Report
'            rtfConfig.Text = logSection.ClientConfig.Report
'            Dim ppProject As New ZedGraph.PointPairList
'            If WU.Frames.Count > 0 Then
'                For xInt As Int32 = 0 To WU.Frames.Count - 2
'                    Dim tsFrame As TimeSpan = WU.Frames(xInt + 1).FrameDT - WU.Frames(xInt).FrameDT
'                    ppProject.Add(New XDate(WU.Frames(xInt).FrameDT), tsFrame.TotalDays)
'                Next
'                zgProject.MasterPane.PaneList.Clear()
'                Dim mPane As New GraphPane
'                mPane.AddCurve("", ppProject, Color.Blue)
'                mPane.XAxis.Type = ZedGraph.AxisType.Date
'                mPane.YAxis.Type = AxisType.Date
'                mPane.Rect = SplitContainer3.Panel1.ClientRectangle
'                zgProject.GraphPane = mPane
'                zgProject.AxisChange()
'                zgProject.Refresh()
'            End If
'            If Not IsNothing(WU.Frames) AndAlso WU.Frames.Count > 0 Then
'                Dim dtStart As DateTime = WU.Frames(0).FrameDT
'                Dim dtEnd As DateTime = WU.Frames(WU.Frames.Count - 1).FrameDT
'                Dim tsProject As TimeSpan = dtEnd - dtStart
'                Dim lTS As Long = tsProject.Ticks
'                Dim lTPF As Long = CLng(lTS / CLng(WU.Frames.Count - 1))
'                Dim tsFrame As New TimeSpan(lTPF)
'                rtfPStats.Clear()
'                rtfPStats.AppendText("Downloaded: " & vbTab & WU.dtDownloaded.ToString(strDTFormat) & Environment.NewLine)
'                If WU.Percentage = "100" Then
'                    rtfPStats.AppendText("Completed: " & vbTab & WU.dtCompleted.ToString(strDTFormat) & Environment.NewLine)
'                Else
'                    If WU.CoreStatus <> "" Then
'                        rtfPStats.AppendText("EUE: " & vbTab & vbTab & WU.dtCompleted.ToString(strDTFormat) & Environment.NewLine)
'                    Else
'                        rtfPStats.AppendText("Current progress: " & vbTab & WU.Percentage & Environment.NewLine)
'                    End If
'                End If
'                If New TimeSpan(tsFrame.Ticks).TotalDays >= 1 Then
'                    Try
'                        'rtfPStats.AppendText("TPF:" & vbTab & vbTab & New TimeSpan(tsFrame.Ticks).ToString("s") & Environment.NewLine)
'                    Catch ex As Exception

'                    End Try
'                Else
'                    Try
'                        rtfPStats.AppendText("TPF:" & vbTab & vbTab & New DateTime(tsFrame.Ticks).ToString("HH:mm:ss") & Environment.NewLine)
'                    Catch ex As Exception

'                    End Try
'                End If
'                Dim sPR As String = WU.PRCG.Replace("project:", "") : sPR = sPR.Substring(0, sPR.IndexOf(" "))
'                If WU.CoreStatus <> "" Then
'                    rtfPStats.AppendText("Upload time:" & vbTab & (WU.dtSubmitted - WU.dtCompleted).ToString & Environment.NewLine)
'                    If WU.Percentage = "100" Then
'                        If WU.Credit = "" Then
'                            If projectInfo.Projects.KnownProject(sPR) And WU.ServerResponce.Contains("(400)") Then
'                                rtfPStats.AppendText("Credit:" & vbTab & vbTab & projectInfo.GetEffectivePPD_sqrt(WU.dtDownloaded, WU.dtSubmitted, sPR).Credit & Environment.NewLine)
'                                rtfPStats.AppendText("PPD:" & vbTab & vbTab & projectInfo.GetEffectivePPD_sqrt(dtStart, WU.dtSubmitted, sPR).PPD & Environment.NewLine)
'                            Else
'                                rtfPStats.AppendText("Credit:" & vbTab & vbTab & "unknown" & Environment.NewLine)
'                                rtfPStats.AppendText("PPD:" & vbTab & vbTab & "unknown" & Environment.NewLine)
'                            End If
'                        Else
'                            rtfPStats.AppendText("Credit:" & vbTab & vbTab & WU.Credit & Environment.NewLine)
'                            If projectInfo.Projects.KnownProject(sPR) Then
'                                rtfPStats.AppendText("PPD:" & vbTab & vbTab & projectInfo.GetEffectivePPD_sqrt(dtStart, dtEnd, sPR).PPD & Environment.NewLine)
'                            Else
'                                If WU.dtSubmitted <> #1/1/2000# And WU.ServerResponce.Contains("(400)") Then
'                                    'Code duplication :(
'                                    Dim tsP As TimeSpan = WU.dtSubmitted.Subtract(WU.dtDownloaded)
'                                    Dim iPworth As Integer = CInt(WU.Credit)
'                                    Dim iPPD As Double = 0
'                                    Dim tsDay As TimeSpan = TimeSpan.FromDays(1)
'                                    Do
'                                        If tsDay.Subtract(tsP).TotalSeconds >= 0 Then
'                                            iPPD += iPworth
'                                            tsDay = tsDay.Subtract(tsP)
'                                        Else
'                                            Exit Do
'                                        End If
'                                    Loop
'                                    'get fraction of _tsFrame to be done in remaining seconds
'                                    Dim iRfraction As Double
'                                    If tsDay.TotalSeconds > 0 Then
'                                        iRfraction = tsDay.TotalSeconds / tsP.TotalSeconds
'                                        iPPD += iRfraction * iPworth
'                                    End If
'                                    rtfPStats.AppendText("PPD:" & vbTab & vbTab & (Math.Round(iPPD, 2)).ToString & Environment.NewLine)
'                                Else
'                                    rtfPStats.AppendText("PPD:" & vbTab & vbTab & "unknown" & Environment.NewLine)
'                                End If

'                                ' Can't calculate PPD if unit is not known, as kFactor value is needed ( for anything but gpu wu's )
'                            End If
'                        End If
'                    End If
'                Else
'                    Dim dtEst As DateTime = WU.Frames(WU.Frames.Count - 1).FrameDT.Add(New TimeSpan(tsFrame.Ticks * (100 - CInt(WU.Percentage))))
'                    rtfPStats.AppendText("Estimated completion:" & vbTab & dtEst.ToString(strDTFormat) & Environment.NewLine)
'                    If projectInfo.Projects.KnownProject(sPR) And WU.ServerResponce.Contains("(400)") Then
'                        rtfPStats.AppendText("Estimated credit:" & vbTab & vbTab & projectInfo.GetEffectivePPD_sqrt(WU.dtDownloaded, dtEst, sPR).Credit & Environment.NewLine)
'                        rtfPStats.AppendText("Estimated PPD:" & vbTab & vbTab & projectInfo.GetEffectivePPD_sqrt(dtStart, dtEst, sPR).PPD & Environment.NewLine)
'                    Else
'                        'Check with stored credit in db for this project ( maybe add the project when not in psummary info with only a project and credit field??
'                        rtfPStats.AppendText("Estimated credit:" & vbTab & vbTab & "unknown" & Environment.NewLine)
'                        rtfPStats.AppendText("Estimated PPD:" & vbTab & vbTab & "unknown" & Environment.NewLine)
'                    End If
'                    dtEst = Nothing
'                End If
'            Else
'                rtfPStats.Clear()
'            End If
'        Catch ex As Exception
'            LogWindow.WriteError(ex.Message, Err)
'        End Try
'    End Sub
'    Private Sub lvWU_SelectedIndexChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles lvWU.SelectedIndexChanged
'        Try
'            If bManual Or lvWU.SelectedItems.Count = 0 Then Exit Sub
'            'Clear graph
'            zgProject.MasterPane.PaneList.Clear()
'            Dim nP As New GraphPane
'            nP.Rect = SplitContainer3.Panel1.ClientRectangle
'            zgProject.MasterPane.Add(nP)
'            zgProject.Refresh()
'            'Handle wu 
'            'All clients
'            'All clients, all wu's, local first
'            Dim bFound As Boolean = False
'            For Each Client In LogParser.Clients
'                For Each LogSection In Client.lstLogFiles
'                    If LogSection.dWU.Count > 0 Then
'                        If LogSection.dWU.ContainsKey(lvWU.SelectedItems(0).Tag.ToString) Then
'                            HistoricalWUSelection(LogSection, LogSection.dWU(lvWU.SelectedItems(0).Tag.ToString))
'                            bFound = True
'                            GoTo Found
'                        End If
'                    End If
'                Next
'            Next
'Found:
'            If Not bFound Then
'                MsgBox("Something went wrong... :(")
'            End If
'        Catch ex As Exception
'            LogWindow.WriteError(ex.Message, Err)
'        End Try
'    End Sub
'    Private Sub BrowserToolStripMenuItem_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles BrowserToolStripMenuItem.Click
'        If pBrowser.IsActive Then
'            pBrowser.hideBrowser()
'        Else
'            pBrowser.ShowBrowser()
'        End If
'    End Sub
'    Private _tsFilterHW As String = "", _tsFilterCS As String = "", _tsFiltersSL As String = "", _tsFiltersPR As String = ""
'    'Private Sub tsFilters_DropDownOpening(ByVal sender As Object, ByVal e As System.EventArgs) Handles tsFilters.DropDownOpening
'    '    Try
'    '        'Populate HW and CS selections based on HW and CS available in current log selection
'    '        'Read from logparser object, or.. shortcut and use the listview?
'    '        Dim lCoreStatus As New List(Of String)
'    '        Dim lHW As New List(Of String)
'    '        Dim lSLOT As New List(Of String)
'    '        Dim lPR As New List(Of String)
'    '        If tscmbClient.SelectedIndex = 0 Then
'    '            'All clients, local first 
'    '            If tscmbLFiles.SelectedIndex = 0 Then
'    '                'All logs
'    '                For Each Client In LogParser.Clients
'    '                    For Each LogSection In Client.lstLogFiles
'    '                        For Each lWU In LogSection.lstWU
'    '                            If lWU.CoreStatus <> "" And Not lCoreStatus.Contains(lWU.CoreStatus) Then lCoreStatus.Add(lWU.CoreStatus)
'    '                            If lWU.HW <> "" And Not lHW.Contains(lWU.HW) Then lHW.Add(lWU.HW)
'    '                            If lWU.Slot <> "" And Not lSLOT.Contains(lWU.Slot) Then lSLOT.Add(lWU.Slot)
'    '                            Dim strT As String = lWU.PRCG.Replace("project:", "") : strT = strT.Substring(0, strT.IndexOf(" "))
'    '                            If lWU.PRCG <> "" And Not lPR.Contains(strT) Then lPR.Add(strT)
'    '                        Next
'    '                    Next
'    '                Next

'    '            Else
'    '                'Selected logs
'    '                For Each Client In LogParser.Clients
'    '                    With Client.dLogFiles(tscmbLFiles.Items(tscmbLFiles.SelectedIndex))
'    '                        For Each lWU In .lstWU
'    '                            If lWU.CoreStatus <> "" And Not lCoreStatus.Contains(lWU.CoreStatus) Then lCoreStatus.Add(lWU.CoreStatus)
'    '                            If lWU.HW <> "" And Not lHW.Contains(lWU.HW) Then lHW.Add(lWU.HW)
'    '                            If lWU.Slot <> "" And Not lSLOT.Contains(lWU.Slot) Then lSLOT.Add(lWU.Slot)
'    '                            Dim strT As String = lWU.PRCG.Replace("project:", "") : strT = strT.Substring(0, strT.IndexOf(" "))
'    '                            If lWU.PRCG <> "" And Not lPR.Contains(strT) Then lPR.Add(strT)
'    '                        Next
'    '                    End With
'    '                Next
'    '            End If
'    '        ElseIf tscmbClient.SelectedIndex = 1 Then
'    '            'Local client 
'    '            If tscmbLFiles.SelectedIndex = 0 Then
'    '                'All logs
'    '                For Each LogSection In LogParser.Clients(0).lstLogFiles
'    '                    For Each lWU In LogSection.lstWU
'    '                        If lWU.CoreStatus <> "" And Not lCoreStatus.Contains(lWU.CoreStatus) Then lCoreStatus.Add(lWU.CoreStatus)
'    '                        If lWU.HW <> "" And Not lHW.Contains(lWU.HW) Then lHW.Add(lWU.HW)
'    '                        If lWU.Slot <> "" And Not lSLOT.Contains(lWU.Slot) Then lSLOT.Add(lWU.Slot)
'    '                        Dim strT As String = lWU.PRCG.Replace("project:", "") : strT = strT.Substring(0, strT.IndexOf(" "))
'    '                        If lWU.PRCG <> "" And Not lPR.Contains(strT) Then lPR.Add(strT)
'    '                    Next
'    '                Next
'    '            Else
'    '                'Selected logs
'    '                With LogParser.Clients(0).dLogFiles(tscmbLFiles.Items(tscmbLFiles.SelectedIndex))
'    '                    For Each lWU In .lstWU
'    '                        If lWU.CoreStatus <> "" And Not lCoreStatus.Contains(lWU.CoreStatus) Then lCoreStatus.Add(lWU.CoreStatus)
'    '                        If lWU.HW <> "" And Not lHW.Contains(lWU.HW) Then lHW.Add(lWU.HW)
'    '                        If lWU.Slot <> "" And Not lSLOT.Contains(lWU.Slot) Then lSLOT.Add(lWU.Slot)
'    '                        Dim strT As String = lWU.PRCG.Replace("project:", "") : strT = strT.Substring(0, strT.IndexOf(" "))
'    '                        If lWU.PRCG <> "" And Not lPR.Contains(strT) Then lPR.Add(strT)
'    '                    Next
'    '                End With
'    '            End If
'    '        Else
'    '            'Selected remote client 
'    '            If tscmbLFiles.SelectedIndex = 0 Then
'    '                'All logs
'    '                With LogParser.Clients(tscmbClient.Items(tscmbClient.SelectedIndex))
'    '                    For Each LogSection In .lstLogFiles
'    '                        For Each lWU In LogSection.lstWU
'    '                            If lWU.CoreStatus <> "" And Not lCoreStatus.Contains(lWU.CoreStatus) Then lCoreStatus.Add(lWU.CoreStatus)
'    '                            If lWU.HW <> "" And Not lHW.Contains(lWU.HW) Then lHW.Add(lWU.HW)
'    '                            If lWU.Slot <> "" And Not lSLOT.Contains(lWU.Slot) Then lSLOT.Add(lWU.Slot)
'    '                            Dim strT As String = lWU.PRCG.Replace("project:", "") : strT = strT.Substring(0, strT.IndexOf(" "))
'    '                            If lWU.PRCG <> "" And Not lPR.Contains(strT) Then lPR.Add(strT)
'    '                        Next
'    '                    Next
'    '                End With
'    '            Else
'    '                'Selected log
'    '                With LogParser.Clients(tscmbClient.Items(tscmbClient.SelectedIndex)).dLogFiles(tscmbLFiles.Items(tscmbLFiles.SelectedIndex))
'    '                    For Each lWU In .lstWU
'    '                        If lWU.CoreStatus <> "" And Not lCoreStatus.Contains(lWU.CoreStatus) Then lCoreStatus.Add(lWU.CoreStatus)
'    '                        If lWU.HW <> "" And Not lHW.Contains(lWU.HW) Then lHW.Add(lWU.HW)
'    '                        If lWU.Slot <> "" And Not lSLOT.Contains(lWU.Slot) Then lSLOT.Add(lWU.Slot)
'    '                        Dim strT As String = lWU.PRCG.Replace("project:", "") : strT = strT.Substring(0, strT.IndexOf(" "))
'    '                        If lWU.PRCG <> "" And Not lPR.Contains(strT) Then lPR.Add(strT)
'    '                    Next
'    '                End With
'    '            End If
'    '        End If
'    '        For Each dItem As ToolStripDropDownItem In tsFilter_CS.DropDownItems
'    '            RemoveHandler dItem.Click, eHandlerCS
'    '        Next
'    '        tsFilter_CS.DropDownItems.Clear()
'    '        For Each sCS In lCoreStatus
'    '            tsFilter_CS.DropDownItems.Add(sCS)
'    '            AddHandler tsFilter_CS.DropDownItems(tsFilter_CS.DropDownItems.Count - 1).Click, eHandlerCS
'    '        Next
'    '        For Each dItem As ToolStripDropDownItem In tsFilter_HW.DropDownItems
'    '            RemoveHandler dItem.Click, eHandlerHW
'    '        Next
'    '        tsFilter_HW.DropDownItems.Clear()
'    '        For Each sHW In lHW
'    '            tsFilter_HW.DropDownItems.Add(sHW)
'    '            AddHandler tsFilter_HW.DropDownItems(tsFilter_HW.DropDownItems.Count - 1).Click, eHandlerHW
'    '        Next
'    '        For Each dItem As ToolStripDropDownItem In tsFilter_SL.DropDownItems
'    '            RemoveHandler dItem.Click, eHandlerSL
'    '        Next
'    '        tsFilter_SL.DropDownItems.Clear()
'    '        For Each sSL In lSLOT
'    '            tsFilter_SL.DropDownItems.Add(sSL)
'    '            AddHandler tsFilter_SL.DropDownItems(tsFilter_SL.DropDownItems.Count - 1).Click, eHandlerSL
'    '        Next
'    '        For Each dItem As ToolStripDropDownItem In tsFilter_PR.DropDownItems
'    '            RemoveHandler dItem.Click, eHandlerPR
'    '        Next
'    '        tsFilter_PR.DropDownItems.Clear()
'    '        For Each sPR In lPR
'    '            tsFilter_PR.DropDownItems.Add(sPR)
'    '            AddHandler tsFilter_PR.DropDownItems(tsFilter_PR.DropDownItems.Count - 1).Click, eHandlerPR
'    '        Next
'    '    Catch ex As Exception
'    '        LogWindow.WriteError(ex.Message, Err)
'    '    End Try
'    'End Sub
'    Private eHandlerPR As New eventhandler(AddressOf dpClickPR)
'    Private Sub dpClickPR(ByVal Sender As Object, ByVal e As System.EventArgs)
'        Try
'            If TypeOf (Sender) Is ToolStripDropDownItem Then
'                With CType(Sender, ToolStripDropDownItem)
'                    _tsFiltersPR = .Text
'                End With
'            End If
'            'Call tscmbLFiles_SelectedIndexChanged(Me, Nothing)
'        Catch ex As Exception

'        End Try
'    End Sub
'    Private eHandlerSL As New eventhandler(AddressOf dpClickSL)
'    Private Sub dpClickSL(ByVal Sender As Object, ByVal e As System.EventArgs)
'        Try
'            If TypeOf (Sender) Is ToolStripDropDownItem Then
'                With CType(Sender, ToolStripDropDownItem)
'                    _tsFiltersSL = .Text
'                End With
'            End If
'            'Call tscmbLFiles_SelectedIndexChanged(Me, Nothing)
'        Catch ex As Exception

'        End Try
'    End Sub
'    Private eHandlerHW As New eventhandler(AddressOf dpClickHW)
'    Private Sub dpClickHW(ByVal Sender As Object, ByVal e As System.EventArgs)
'        Try
'            If TypeOf (Sender) Is ToolStripDropDownItem Then
'                With CType(Sender, ToolStripDropDownItem)
'                    _tsFilterHW = .Text
'                End With
'            End If
'            'Call tscmbLFiles_SelectedIndexChanged(Me, Nothing)
'        Catch ex As Exception

'        End Try
'    End Sub
'    Private eHandlerCS As New eventhandler(AddressOf dpClickCS)
'    Private Sub dpClickCS(ByVal Sender As Object, ByVal e As System.EventArgs)
'        Try
'            If TypeOf (Sender) Is ToolStripDropDownItem Then
'                With CType(Sender, ToolStripDropDownItem)
'                    _tsFilterCS = .Text
'                End With
'            End If
'            'Call tscmbLFiles_SelectedIndexChanged(Me, Nothing)
'        Catch ex As Exception

'        End Try
'    End Sub
'    Private Sub ClearToolStripMenuItem_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles ClearToolStripMenuItem.Click
'        _tsFilterCS = "" : _tsFilterHW = "" : _tsFiltersPR = "" : _tsFiltersSL = ""
'        'Call tscmbLFiles_SelectedIndexChanged(Me, Nothing)
'    End Sub
'    Private Sub AboutToolStripMenuItem_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles AboutToolStripMenuItem.Click
'        About.ShowAbout(Me)
'    End Sub
'    Private Sub frmFWatch_FormClosed(ByVal sender As Object, ByVal e As System.Windows.Forms.FormClosedEventArgs) Handles Me.FormClosed
'        Try
'            zgProject = Nothing
'        Catch ex As Exception

'        End Try
'    End Sub
'    Private Sub ViewDiagnosticsToolStripMenuItem_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles ViewDiagnosticsToolStripMenuItem.Click
'        Try
'            Dim fDiag As New clsLogwindow
'            fDiag.Form.rtLog.Text = Diagnostic
'            fDiag.Form.ShowDialog(Me)
'            fDiag = Nothing
'        Catch ex As Exception

'        End Try
'    End Sub
'    Private Sub ExitToolStripMenuItem_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles ExitToolStripMenuItem.Click
'        Application.Exit()
'    End Sub
'    'Private Sub RClientsToolStripMenuItem_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles RClientsToolStripMenuItem.Click
'    '    Try
'    '        If mySettings.RemoteClients.IsFormActive Then
'    '            'mysettings.RemoteClients.ActivateForm
'    '        Else
'    '            mySettings.RemoteClients.ShowForm(Me)
'    '        End If
'    '    Catch ex As Exception

'    '    End Try
'    'End Sub
'    Private Sub tRef_Tick(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles tRef.Tick
'        Try
'            If Not Me.Created Then Exit Sub
'            If dtLastRefresh = #1/1/2000# Then Exit Sub
'            If Not mySettings.LiveView Then
'                tsRefresh.Text = "Dynamic updates disabeld"
'                Exit Sub
'            Else
'                Dim tsR As TimeSpan = dtLastRefresh.AddSeconds(mySettings.UpdateInterval).Subtract(DateTime.Now)
'                Dim strM As String
'                If tsR.Minutes < 10 Then
'                    strM = "0" & tsR.Minutes.ToString
'                Else
'                    strM = tsR.Minutes.ToString
'                End If
'                If tsR.Seconds < 10 Then
'                    strM &= ":0" & tsR.Seconds.ToString
'                Else
'                    strM &= ":" & tsR.Seconds.ToString
'                End If
'                tsRefresh.Text = "Next refresh in: " & strM
'                strM = Nothing : tsR = Nothing
'            End If
'            If DateTime.Now >= dtLastRefresh.AddSeconds(mySettings.UpdateInterval) Then
'                dtLastRefresh = DateTime.Now
'                LogParser.ParseLogs()
'                UpdateActive()
'                'Not very nice I know but will be changed, I'm rushing things abit since I wanted to finish this over the weekend :(
'                'If bgActive.IsBusy Then

'                'Else
'                '    bgActive.RunWorkerAsync()
'                '    dtLastRefresh = DateTime.Now
'                'End If
'            End If
'        Catch ex As Exception
'            LogWindow.WriteError(ex.Message, Err)
'        End Try
'    End Sub
'    Private Sub ActiveWU_Info(ByVal LogSection As clsLogParser.clsClient.clsLogFile, ByVal WU As clsLogParser.clsClient.clsLogFile.clsWU)
'        Try
'            rtfSnippet.Text = WU.CoreSnippet
'            rtfClient.Text = LogSection.ClientInfo.Report
'            rtfConfig.Text = LogSection.ClientConfig.Report
'            Dim ppProject As New ZedGraph.PointPairList
'            If WU.Frames.Count > 0 Then
'                For xInt As Int16 = 0 To WU.Frames.Count - 2
'                    Dim tsFrame As TimeSpan = WU.Frames(xInt + 1).FrameDT - WU.Frames(xInt).FrameDT
'                    ppProject.Add(New XDate(WU.Frames(xInt).FrameDT), tsFrame.TotalDays)
'                Next
'                zgProject.MasterPane.PaneList.Clear()
'                Dim mPane As New GraphPane
'                mPane.AddCurve("", ppProject, Color.Blue)
'                mPane.XAxis.Type = ZedGraph.AxisType.Date
'                mPane.YAxis.Type = AxisType.Date
'                mPane.Rect = SplitContainer3.Panel1.ClientRectangle
'                zgProject.GraphPane = mPane
'                zgProject.AxisChange()
'                zgProject.Refresh()
'            End If
'            If Not IsNothing(WU.Frames) AndAlso WU.Frames.Count > 0 Then
'                Dim dtStart As DateTime = WU.Frames(0).FrameDT
'                Dim dtEnd As DateTime = WU.Frames(WU.Frames.Count - 1).FrameDT
'                Dim tsProject As TimeSpan = dtEnd - dtStart
'                Dim lTS As Long = tsProject.Ticks
'                Dim lTPF As Long = CLng(lTS / CLng(WU.Frames.Count) - 1)
'                Dim tsFrame As New TimeSpan(lTPF)
'                rtfPStats.Clear()
'                rtfPStats.AppendText("Downloaded: " & vbTab & vbTab & WU.dtDownloaded.ToString(strDTFormat) & Environment.NewLine)
'                If WU.Percentage = "100" Then
'                    rtfPStats.AppendText("Completed: " & vbTab & WU.dtCompleted.ToString(strDTFormat) & Environment.NewLine)
'                Else
'                    If WU.CoreStatus <> "" Then
'                        rtfPStats.AppendText("EUE: " & vbTab & vbTab & WU.dtCompleted.ToString(strDTFormat) & Environment.NewLine)
'                    Else
'                        rtfPStats.AppendText("Current progress: " & vbTab & vbTab & WU.Percentage & Environment.NewLine)
'                    End If
'                End If
'                rtfPStats.AppendText("Last frame completed: " & vbTab & WU.Frames(WU.Frames.Count - 1).FrameDT.ToString(strDTFormat) & vbNewLine)
'                If New TimeSpan(tsFrame.Ticks).TotalDays >= 1 Then
'                    Try
'                        rtfPStats.AppendText("TPF:" & vbTab & vbTab & vbTab & New TimeSpan(tsFrame.Ticks).ToString("dd:HH:mm:ss") & Environment.NewLine)
'                    Catch ex As Exception

'                    End Try
'                Else
'                    Try
'                        rtfPStats.AppendText("TPF:" & vbTab & vbTab & vbTab & New DateTime(tsFrame.Ticks).ToString("HH:mm:ss") & Environment.NewLine)
'                    Catch ex As Exception

'                    End Try
'                End If
'                Dim sPR As String = WU.PRCG.Replace("project:", "") : sPR = sPR.Substring(0, sPR.IndexOf(" "))
'                If WU.CoreStatus <> "" Then
'                    rtfPStats.AppendText("Upload time:" & vbTab & (WU.dtSubmitted - WU.dtCompleted).ToString & Environment.NewLine)
'                    If WU.Percentage = "100" Then
'                        If WU.Credit = "" Then
'                            If projectInfo.Projects.KnownProject(sPR) And WU.ServerResponce.Contains("(400)") Then
'                                rtfPStats.AppendText("Credit:" & vbTab & vbTab & projectInfo.GetEffectivePPD_sqrt(WU.dtDownloaded, WU.dtSubmitted, sPR).Credit & Environment.NewLine)
'                                rtfPStats.AppendText("PPD:" & vbTab & vbTab & projectInfo.GetEffectivePPD_sqrt(dtStart, WU.dtSubmitted, sPR).PPD & Environment.NewLine)
'                            Else
'                                rtfPStats.AppendText("Credit:" & vbTab & vbTab & "unknown" & Environment.NewLine)
'                                rtfPStats.AppendText("PPD:" & vbTab & vbTab & "unknown" & Environment.NewLine)
'                            End If
'                        Else
'                            rtfPStats.AppendText("Credit:" & vbTab & vbTab & WU.Credit & Environment.NewLine)
'                            If projectInfo.Projects.KnownProject(sPR) Then
'                                rtfPStats.AppendText("PPD:" & vbTab & vbTab & projectInfo.GetEffectivePPD_sqrt(dtStart, dtEnd, sPR).PPD & Environment.NewLine)
'                            Else
'                                If WU.dtSubmitted <> #1/1/2000# And WU.ServerResponce.Contains("(400)") Then
'                                    'Code duplication :(
'                                    Dim tsP As TimeSpan = WU.dtSubmitted.Subtract(WU.dtDownloaded)
'                                    Dim iPworth As Integer = CInt(WU.Credit)
'                                    Dim iPPD As Double = 0
'                                    Dim tsDay As TimeSpan = TimeSpan.FromDays(1)
'                                    Do
'                                        If tsDay.Subtract(tsP).TotalSeconds >= 0 Then
'                                            iPPD += iPworth
'                                            tsDay = tsDay.Subtract(tsP)
'                                        Else
'                                            Exit Do
'                                        End If
'                                    Loop
'                                    'get fraction of _tsFrame to be done in remaining seconds
'                                    Dim iRfraction As Double
'                                    If tsDay.TotalSeconds > 0 Then
'                                        iRfraction = tsDay.TotalSeconds / tsP.TotalSeconds
'                                        iPPD += iRfraction * iPworth
'                                    End If
'                                    rtfPStats.AppendText("PPD:" & vbTab & vbTab & (Math.Round(iPPD, 2)).ToString & Environment.NewLine)
'                                Else
'                                    rtfPStats.AppendText("PPD:" & vbTab & vbTab & "unknown" & Environment.NewLine)
'                                End If

'                                ' Can't calculate PPD if unit is not known, as kFactor value is needed ( for anything but gpu wu's )
'                            End If
'                        End If
'                    End If
'                Else
'                    Dim dtEst As DateTime = WU.Frames(WU.Frames.Count - 1).FrameDT.ToLocalTime.Add(New TimeSpan(tsFrame.Ticks * (100 - CInt(WU.Percentage))))
'                    rtfPStats.AppendText("Estimated completion:" & vbTab & dtEst.ToString(strDTFormat) & Environment.NewLine)
'                    If projectInfo.Projects.KnownProject(sPR) Then
'                        rtfPStats.AppendText("Estimated credit:" & vbTab & vbTab & projectInfo.GetEffectivePPD_sqrt(WU.dtDownloaded, dtEst, sPR).Credit & Environment.NewLine)
'                        rtfPStats.AppendText("Estimated PPD:" & vbTab & vbTab & projectInfo.GetEffectivePPD_sqrt(dtStart, dtEst, sPR).PPD & Environment.NewLine)
'                    Else
'                        'Check with stored credit in db for this project ( maybe add the project when not in psummary info with only a project and credit field??
'                        rtfPStats.AppendText("Estimated credit:" & vbTab & vbTab & "unknown" & Environment.NewLine)
'                        rtfPStats.AppendText("Estimated PPD:" & vbTab & vbTab & "unknown" & Environment.NewLine)
'                    End If
'                    dtEst = Nothing
'                End If
'            Else
'                rtfPStats.Clear()
'            End If
'        Catch ex As Exception
'            LogWindow.WriteError(ex.Message, Err)
'        End Try
'    End Sub
'    Private Sub lvActive_SelectedIndexChanged(ByVal sender As Object, ByVal e As System.EventArgs)
'        'Try
'        '    If lvActive.Items.Count = 0 Or lvActive.SelectedItems.Count = 0 Then Exit Sub
'        '    For Each Client In LogParser.Clients
'        '        For Each LogSection In Client.lstLogFiles
'        '            If LogSection.dWU.Contains(lvActive.SelectedItems(0).Tag) Then
'        '                ActiveWU_Info(LogSection, LogSection.dWU(lvActive.SelectedItems(0).Tag))
'        '                Exit Sub
'        '            End If
'        '        Next
'        '    Next
'        'Catch ex As Exception
'        '    LogWindow.WriteError(ex.Message, Err)
'        'End Try
'    End Sub
'    'Private Sub tsCmdRefresh_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles tsCmdRefresh.Click
'    '    Try
'    '        LogParser.ParseLogs()
'    '        For Each rP In rLogParser
'    '            rP.ParseLogs()
'    '        Next
'    '        RefreshUI()
'    '        'UpdateActive()
'    '        'Not very nice I know but will be changed, I'm rushing things abit since I wanted to finish this over the weekend :(
'    '        'If bgActive.IsBusy Then

'    '        'Else
'    '        '    bgActive.RunWorkerAsync()
'    '        '    dtLastRefresh = DateTime.Now
'    '        'End If
'    '    Catch ex As Exception
'    '        LogWindow.WriteError(ex.Message, Err)
'    '    End Try
'    'End Sub
'    Public Sub UpdateActive()
'        'Try
'        '    'ClearActive()
'        '    dtLastRefresh = DateTime.Now
'        '    lvActive.Items.Clear()
'        '    lvActive.SuspendLayout()
'        '    'SuspendActive()
'        '    For Each Client As clsLogParser.clsClient In LogParser.Clients
'        '        For Each logSection As clsLogParser.clsClient.clsLogFile In Client.lstLogfiles
'        '            For Each wu As clsLogParser.clsClient.clsLogFile.clsWU In logSection.lstWU
'        '                'If wu.dtSubmitted = #1/1/2001# Then
'        '                If wu.CoreStatus = "" Then
'        '                    'Assume unit is active?
'        '                    Dim nI As New ListViewItem
'        '                    nI.Text = Client.ClientName
'        '                    nI.SubItems.Add(wu.Slot)
'        '                    nI.SubItems.Add(wu.HW)
'        '                    nI.SubItems.Add(wu.PRCG)
'        '                    nI.SubItems.Add(wu.dtDownloaded.ToString(strDTFormat))
'        '                    If wu.Frames.Count > 0 Then
'        '                        Dim dtStart As DateTime = wu.Frames(0).FrameDT
'        '                        Dim dtEnd As DateTime = wu.Frames(wu.Frames.Count - 1).FrameDT
'        '                        Dim tsProject As TimeSpan = dtEnd - dtStart
'        '                        Dim lTS As Long = tsProject.Ticks
'        '                        Dim lTPF As Long = lTS / wu.Frames.Count - 1
'        '                        Dim tsFrame As New TimeSpan(lTPF)
'        '                        Dim dtEst As DateTime = wu.Frames(wu.Frames.Count - 1).FrameDT.Add(New TimeSpan(tsFrame.Ticks * (100 - CInt(wu.Percentage))))
'        '                        nI.SubItems.Add(dtEst.ToString(strDTFormat))
'        '                        nI.SubItems.Add(wu.Percentage)
'        '                        nI.SubItems.Add(wu.Core)
'        '                        nI.SubItems.Add(wu.CoreVersion)
'        '                        Dim sPR As String = wu.PRCG.Replace("project:", "") : sPR = sPR.Substring(0, sPR.IndexOf(" "))
'        '                        If projectInfo.Projects.KnownProject(sPR) Then
'        '                            nI.SubItems.Add(projectInfo.GetEffectivePPD_sqrt(wu.dtDownloaded, dtEst, sPR).Credit)
'        '                            nI.SubItems.Add(projectInfo.GetEffectivePPD_sqrt(wu.dtDownloaded, dtEst, sPR).PPD)
'        '                            nI.BackColor = Color.LightBlue
'        '                        Else
'        '                            'Check with stored credit in db for this project ( maybe add the project when not in psummary info with only a project and credit field??
'        '                            nI.SubItems.Add("") : nI.SubItems.Add("")
'        '                            nI.BackColor = Color.LightGreen
'        '                        End If
'        '                        Dim dtNFrame As DateTime = wu.Frames(wu.Frames.Count - 1).FrameDT.ToLocalTime.Add(tsFrame)
'        '                        If dtNFrame.Subtract(DateTime.Now).TotalSeconds < 0 Then
'        '                            nI.BackColor = Color.Yellow
'        '                        End If
'        '                        If dtNFrame.AddMinutes(5).Subtract(DateTime.Now).TotalSeconds < 0 Then
'        '                            nI.BackColor = Color.Orange
'        '                        End If
'        '                        If dtNFrame.AddMinutes(10).Subtract(DateTime.Now).TotalSeconds < 0 Then
'        '                            nI.BackColor = Color.Red
'        '                        End If
'        '                        dtEst = Nothing : tsFrame = Nothing : dtStart = Nothing : dtEnd = Nothing : lTPF = Nothing : lTS = Nothing : sPR = Nothing
'        '                    Else
'        '                        nI.SubItems.Add("")
'        '                        nI.SubItems.Add(wu.Percentage)
'        '                        nI.SubItems.Add(wu.Core)
'        '                        nI.SubItems.Add(wu.CoreVersion)
'        '                        nI.SubItems.Add("") : nI.SubItems.Add("")
'        '                        nI.BackColor = Color.Yellow
'        '                    End If
'        '                    'AddDynamic(nI)
'        '                    nI.SubItems.Add(wu.bHasRestarted.ToString)
'        '                    nI.Tag = wu.unit
'        '                    lvActive.Items.Add(nI)
'        '                End If
'        '            Next
'        '        Next
'        '    Next

'        '    'For Each rP In rLogParser
'        '    '    For Each logSection As clsLogParser.clsLogFile In rP.lstLogfiles
'        '    '        For Each wu As clsLogParser.clsLogFile.clsWU In logSection.lstwu
'        '    '            'If wu.dtSubmitted = #1/1/2000# Then
'        '    '            If wu.CoreStatus = "" Then
'        '    '                'Assume unit is active?
'        '    '                Dim nI As New ListViewItem
'        '    '                nI.Text = rP.ClientName
'        '    '                nI.SubItems.Add(wu.Slot)
'        '    '                nI.SubItems.Add(wu.HW)
'        '    '                nI.SubItems.Add(wu.PRCG)
'        '    '                nI.SubItems.Add(wu.dtDownloaded.ToString(strDTFormat))
'        '    '                If wu.Frames.Count > 0 Then
'        '    '                    Dim dtStart As DateTime = wu.Frames(0).FrameDT
'        '    '                    Dim dtEnd As DateTime = wu.Frames(wu.Frames.Count - 1).FrameDT
'        '    '                    Dim tsProject As TimeSpan = dtEnd - dtStart
'        '    '                    Dim lTS As Long = tsProject.Ticks
'        '    '                    Dim lTPF As Long = lTS / wu.Frames.Count - 1
'        '    '                    Dim tsFrame As New TimeSpan(lTPF)
'        '    '                    Dim dtEst As DateTime = wu.Frames(wu.Frames.Count - 1).FrameDT.Add(New TimeSpan(tsFrame.Ticks * (100 - CInt(wu.Percentage))))
'        '    '                    nI.SubItems.Add(dtEst.ToString(strDTFormat))
'        '    '                    nI.SubItems.Add(wu.Percentage)
'        '    '                    nI.SubItems.Add(wu.Core)
'        '    '                    nI.SubItems.Add(wu.CoreVersion)
'        '    '                    Dim sPR As String = wu.PRCG.Replace("project:", "") : sPR = sPR.Substring(0, sPR.IndexOf(" "))
'        '    '                    If projectInfo.Projects.KnownProject(sPR) Then
'        '    '                        nI.SubItems.Add(projectInfo.GetEffectivePPD_sqrt(wu.dtDownloaded, dtEst, sPR).Credit)
'        '    '                        nI.SubItems.Add(projectInfo.GetEffectivePPD_sqrt(wu.dtDownloaded, dtEst, sPR).PPD)
'        '    '                        nI.BackColor = Color.LightBlue
'        '    '                    Else
'        '    '                        'Check with stored credit in db for this project ( maybe add the project when not in psummary info with only a project and credit field??
'        '    '                        nI.SubItems.Add("") : nI.SubItems.Add("")
'        '    '                        nI.BackColor = Color.LightGreen
'        '    '                    End If
'        '    '                    Dim dtNFrame As DateTime = wu.Frames(wu.Frames.Count - 1).FrameDT.ToLocalTime.Add(tsFrame)
'        '    '                    If dtNFrame.Subtract(DateTime.Now).TotalSeconds < 0 Then
'        '    '                        nI.BackColor = Color.Yellow
'        '    '                    End If
'        '    '                    If dtNFrame.AddMinutes(5).Subtract(DateTime.Now).TotalSeconds < 0 Then
'        '    '                        nI.BackColor = Color.Orange
'        '    '                    End If
'        '    '                    If dtNFrame.AddMinutes(10).Subtract(DateTime.Now).TotalSeconds < 0 Then
'        '    '                        nI.BackColor = Color.Red
'        '    '                    End If
'        '    '                    dtEst = Nothing : tsFrame = Nothing : dtStart = Nothing : dtEnd = Nothing : lTPF = Nothing : lTS = Nothing : sPR = Nothing
'        '    '                Else
'        '    '                    nI.SubItems.Add("")
'        '    '                    nI.SubItems.Add(wu.Percentage)
'        '    '                    nI.SubItems.Add(wu.Core)
'        '    '                    nI.SubItems.Add(wu.CoreVersion)
'        '    '                    nI.SubItems.Add("") : nI.SubItems.Add("")
'        '    '                    nI.BackColor = Color.Yellow
'        '    '                End If
'        '    '                nI.SubItems.Add(wu.bHasRestarted.ToString)
'        '    '                'AddDynamic(nI)
'        '    '                lvActive.Items.Add(nI)
'        '    '            End If
'        '    '        Next
'        '    '    Next
'        '    'Next
'        '    'StopSuspendLayout()
'        '    lvActive.ResumeLayout(True)
'        '    lvActive.AutoResizeColumns(ColumnHeaderAutoResizeStyle.ColumnContent)
'        '    lvActive.AutoResizeColumns(ColumnHeaderAutoResizeStyle.HeaderSize)
'        'Catch ex As Exception
'        '    LogWindow.WriteError(ex.Message, Err)
'        'End Try
'    End Sub


'End Class
